package com.sm.li.entity.base;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.sm.li.common.valid.group.AddGroup;
import com.sm.li.common.valid.group.UpdateGroup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NonNull;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
public class BaseEntity implements Serializable {

    @ExcelProperty(value = "员工id",index = 0)
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "角色id")
    @Null(message = "添加时id必须为空",groups ={AddGroup.class} )
    @NotNull(message = "修改时id不能为空",groups = {UpdateGroup.class})
    private Long id;

    @ExcelIgnore
    @ApiModelProperty(value = "创建者")
    @JsonIgnore
    private Long createBy;

    @ExcelIgnore
    @ApiModelProperty(value = "创建时间")
    @JsonIgnore
    private LocalDateTime createTime;

    @ExcelIgnore
    @ApiModelProperty(value = "修改者")
    @JsonIgnore
    private Long updateBy;

    @ExcelIgnore
    @ApiModelProperty(value = "修改时间")
    @JsonIgnore
    private LocalDateTime updateTime;
    //添加数据
    public void setData(){
        if (id==null){
            this.createBy=1L;
            this.createTime=LocalDateTime.now();
        }else {
            this.updateBy=2L;
            this.updateTime=LocalDateTime.now();
        }
    }
}
